Loading packages for the plots

library(ggplot2)
library(plotly)
library(flexdashboard)
library(dplyr)
library(tidyverse)
library(leaflet)
library(knitr)

Reading in Cleaned Data

alcohol_data_2007 = read_csv("./data/PRAM_2007_alcohol.csv")

tobacco_data_2007 = read_csv("./data/PRAM_2007_tobacco.csv")

no_contraception_data_2007 = read_csv("./data/PRAM_2007_no_contraception.csv")

infant_mortality_df = read_csv("./data/PRAM_2007_infantmortality.csv")

maternal_race = read_csv("./data/PRAM_2007_Maternal_Race.csv")

# cleaned alcohol data 
cleaned_alc_2007 <- alcohol_data_2007 |>
  janitor::clean_names() |>
  select(-data_value_std_err, -data_value_type) |>
  filter(response != "DRINKER WHO QUIT") |>
  filter(response != "NONDRINKER") |>
  filter( response != "NO") |>
  drop_na(response,geolocation) |>
  separate(geolocation, into = c("latitude", "longitude"), sep = ", ", convert = TRUE) |>
   mutate(latitude = as.numeric(str_replace_all(latitude, "\\(|\\)", "")),  # Convert to numeric and remove parentheses
         longitude = as.numeric(str_replace_all(longitude, "\\(|\\)", "")))  # Convert to numeric and remove parentheses

# cleaned tobacco data 

cleaned_tobac_2007 <- tobacco_data_2007 |>
  janitor::clean_names() |>
  select(-data_value_type) |>
  filter(response != "SMOKER WHO QUIT") |>
  filter(response != "NONSMOKER") |>
  filter(response != "None (0 cig)") |>
  filter( response != "NO") |>
  drop_na(response, geolocation) |>
  separate(geolocation, into = c("latitude", "longitude"), sep = ", ", convert = TRUE) |>
   mutate(latitude = as.numeric(str_replace_all(latitude, "\\(|\\)", "")),  # Convert to numeric and remove parentheses
         longitude = as.numeric(str_replace_all(longitude, "\\(|\\)", "")))  # Convert to numeric and remove parentheses

cleaned_mat_race <- maternal_race |>
  janitor::clean_names() |>
  select(-data_value_std_err, -data_value_type) |>
  drop_na(response,geolocation) |>
  separate(geolocation, into = c("latitude", "longitude"), sep = ", ", convert = TRUE) |>
   mutate(latitude = as.numeric(str_replace_all(latitude, "\\(|\\)", "")),  # Convert to numeric and remove parentheses
         longitude = as.numeric(str_replace_all(longitude, "\\(|\\)", "")))  # Convert to numeric and remove parentheses
  
no_alcohol_data_2007 = read_csv("./data/PRAM_2007_no_alcohol.csv")

no_tobacco_data_2007 = read_csv("./data/PRAM_2007_no_tobacco.csv")

contraception_data_2007 = read_csv("./data/PRAM_2007_contraception.csv")

# cleaned no alcohol data 

cleaned_no_alc_2007 <- no_alcohol_data_2007 |>
  janitor::clean_names() |>
  select(-data_value_std_err, -geolocation, -data_value_type) |>
  drop_na(response)

view(cleaned_no_alc_2007)

# cleaned no tobacco data 

cleaned_no_tobacco_2007 <- no_tobacco_data_2007 |>
  janitor::clean_names() |>
  select(-data_value_std_err, -geolocation, -data_value_type) |>
  drop_na(response)

# cleaned infant mortality 

cleaned_infant_mortality <- infant_mortality_df |>
  janitor::clean_names() |>
  select(-data_value_std_err, -data_value_type, -data_value_unit, -data_value_footnote_symbol, -data_value_footnote) |>
  drop_na(response, geolocation) |>
  separate(geolocation, into = c("latitude", "longitude"), sep = ", ", convert = TRUE) |>
   mutate(latitude = as.numeric(str_replace_all(latitude, "\\(|\\)", "")),  # Convert to numeric and remove parentheses
         longitude = as.numeric(str_replace_all(longitude, "\\(|\\)", "")))  # Convert to numeric and remove parentheses

# cleaned conception

cleaned_contraception_2007 <- contraception_data_2007 |>
  janitor::clean_names() |>
  select(-data_value_std_err, -geolocation, -data_value_type) |>
  filter(response != "YES (CHECKED)") |>
  filter(response != "YES") |>
  drop_na(response)

# cleaned non conception

cleaned_no_contra_2007 <- no_contraception_data_2007 %>%
  janitor::clean_names() %>%
  select(-data_value_type) %>%
  drop_na(response) |>
  separate(geolocation, into = c("latitude", "longitude"), sep = ", ", convert = TRUE) |>
   mutate(latitude = as.numeric(str_replace_all(latitude, "\\(|\\)", "")),  # Convert to numeric and remove parentheses
         longitude = as.numeric(str_replace_all(longitude, "\\(|\\)", "")))  # Convert to numeric and remove parentheses

Plot 1: Alcohol Consumption in relation to Infant Mortality

# Plot of question and responses for alcohol

# Create ggplot object
gg_plot <- cleaned_alc_2007 %>%
  ggplot(aes(x = question, fill = response)) +
  geom_bar(position = "dodge") +
  labs(title = "Questions and Responses", x = "Questions", y = "Count") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 5, size = 2)) +
  labs(
    x = "Question",
    y = "Response",
    title = "Questions vs Response of Alcohol Consumption"
  )

# Extract data directly from the original data frame
plot_data <- cleaned_alc_2007 %>%
  group_by(question, response) %>%
  summarize(count = n())

# Convert data to Plotly
plot_ly(data = plot_data, x = ~question, y = ~count, color = ~response, type = "bar", split = ~response) %>%
  layout(
    title = "Questions vs Response of Alcohol Consumption",
    xaxis = list(title = "Question",tickfont = list(size = 5)),
    yaxis = list(title = "Response"),
    barmode = "stack"
  )
<<<<<<< HEAD
=======
>>>>>>> 61515ee613fd1157b231ac2f912d6536743abd6f

Plot 2: Tobacco Plots

library(ggplot2)
library(plotly)
library(dplyr)

# Assuming cleaned_tobac_2007 is a data frame
# If not, convert it to a data frame using as.data.frame()

# Create ggplot object
gg_plot <- cleaned_tobac_2007 %>%
  ggplot(aes(x = location_abbr, fill = response)) +
  geom_bar(position = "dodge") +
  labs(title = "Questions and Responses", x = "Questions", y = "Count") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(
    x = "Question",
    y = "Response",
    title = "Tobacco Use by State"
  )

# Extract data directly from the original data frame
plot_data <- cleaned_tobac_2007 %>%
  group_by(location_abbr, response) %>%
  summarize(count = n())
## `summarise()` has grouped output by 'location_abbr'. You can override using the
## `.groups` argument.
# Convert data to Plotly
plot_ly(data = plot_data, x = ~location_abbr, y = ~count, color = ~response, type = "bar", split = ~response) %>%
  layout(
    title = " Tobacco Use by State",
    xaxis = list(title = "Question"),
    yaxis = list(title = "Response"),
    barmode = "stack"
  )
<<<<<<< HEAD
=======
>>>>>>> 61515ee613fd1157b231ac2f912d6536743abd6f

Map of Maternal Alcohol Use

leaflet() |> 
  addTiles() |> 
  addCircleMarkers(data = cleaned_alc_2007,
                   lng = ~longitude,  # Adjust column name if needed
                   lat = ~latitude,   # Adjust column name if needed
                   label = ~location_abbr,   # Assuming 'Group.1' is a column in your data
                   radius = 7,
                   color = "orange",
                   stroke = TRUE,
                   fillOpacity = 0.75,
                   popup = ~paste("Response:", response)) 
<<<<<<< HEAD
=======
>>>>>>> 61515ee613fd1157b231ac2f912d6536743abd6f

Map of Maternal Tobacco use

leaflet() |> 
  addTiles() |> 
  addCircleMarkers(data = cleaned_tobac_2007,
                   lng = ~longitude,  # Adjust column name if needed
                   lat = ~latitude,   # Adjust column name if needed
                   label = ~location_abbr,   # Assuming 'Group.1' is a column in your data
                   radius = 7,
                   color = "orange",
                   stroke = TRUE,
                   fillOpacity = 0.75,
                   popup = ~paste("Response:", response)) 
<<<<<<< HEAD
=======
>>>>>>> 61515ee613fd1157b231ac2f912d6536743abd6f

Map of Infant Mortality Rate

leaflet() |> 
  addTiles() |> 
  addCircleMarkers(data = cleaned_infant_mortality,
                   lng = ~longitude,  # Adjust column name if needed
                   lat = ~latitude,   # Adjust column name if needed
                   label = ~location_abbr,   # Assuming 'Group.1' is a column in your data
                   radius = 7,
                   color = "orange",
                   stroke = TRUE,
                   fillOpacity = 0.75,
                   popup = ~paste("Response:", response))
<<<<<<< HEAD
=======
>>>>>>> 61515ee613fd1157b231ac2f912d6536743abd6f

States with the most infant mortality rates

The plot above shows the locations of infant mortality rate across the US.

infant_deaths <- cleaned_infant_mortality %>%
  filter(question == "Indicator of infant currently alive" & response == "NO") %>%
  group_by(location_desc) %>%
  summarize(total_infant_deaths = n())

# Display the table using knitr::kable()
knitr::kable(infant_deaths)
location_desc total_infant_deaths
Alaska 45
Arkansas 45
Colorado 47
Delaware 40
Georgia 43
Hawaii 45
Illinois 47
Maine 42
Maryland 45
Massachusetts 44
Michigan 43
Minnesota 41
Missouri 42
Nebraska 45
New Jersey 39
New York (excluding NYC) 47
New York City 47
North Carolina 47
Ohio 46
Oklahoma 47
Oregon 46
Pennsylvania 3
Rhode Island 46
South Carolina 47
South Dakota 43
Utah 47
Vermont 47
Washington 43
West Virginia 47
Wisconsin 40
Wyoming 43

The table provides a summary of total infant deaths by state, with each row representing a specific location. The location_desc column denotes the state, and the total_infant_deaths column indicates the corresponding number of infant deaths in each location. The data suggests variability in infant mortality rates across different regions, with some areas reporting higher or lower rates than others. For instance, states like Pennsylvania have a notably lower count of infant deaths, while others, such as Alaska and Arkansas, have higher counts. However, most of the data seemed to stay within the 35 to 50 range. This summary provides an overview of the distribution of infant deaths across various geographical locations.

Plot of Infant Mortality and Race/Ethnicity

filtered_mortality_race <- cleaned_infant_mortality %>%
  filter(break_out_category == "Maternal Race/Ethnicity" &
         (break_out %in% c("Hispanic", "Non-hispanic", "White, non-Hispanic")) &
         question == "Indicator of infant currently alive" & response == "NO")

# Display the table using knitr::kable()
knitr::kable(filtered_mortality_race)
year location_abbr location_desc class topic question data_source response data_value low_confidence_limit high_confidence_limit sample_size break_out break_out_category latitude longitude class_id topic_id question_id location_id break_out_id break_out_categoryid response_id
2007 UT Utah Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.9 0.3 2.7 5 Hispanic Maternal Race/Ethnicity 39.36070 -111.58713 CLA8 TOP43 QUO143 49 ETH2 BOC6 RES23
2007 OR Oregon Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.7 0.2 2.1 3 Hispanic Maternal Race/Ethnicity 44.56745 -120.15503 CLA8 TOP43 QUO143 41 ETH2 BOC6 RES23
2007 WA Washington Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.2 0.0 1.7 1 White, non-Hispanic Maternal Race/Ethnicity 47.52228 -120.47001 CLA8 TOP43 QUO143 53 ETH4 BOC6 RES23
2007 YC New York City Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.4 0.2 0.7 10 Hispanic Maternal Race/Ethnicity 42.82700 -75.54397 CLA8 TOP43 QUO143 36 ETH2 BOC6 RES23
2007 OH Ohio Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.6 0.3 1.4 18 White, non-Hispanic Maternal Race/Ethnicity 40.06021 -82.40426 CLA8 TOP43 QUO143 39 ETH4 BOC6 RES23
2007 ME Maine Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO NA NA NA NA Hispanic Maternal Race/Ethnicity 45.25423 -68.98503 CLA8 TOP43 QUO143 23 ETH2 BOC6 RES23
2007 MD Maryland Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.6 0.3 1.3 7 Hispanic Maternal Race/Ethnicity 39.29058 -76.60926 CLA8 TOP43 QUO143 24 ETH2 BOC6 RES23
2007 ME Maine Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.3 0.2 0.4 19 White, non-Hispanic Maternal Race/Ethnicity 45.25423 -68.98503 CLA8 TOP43 QUO143 23 ETH4 BOC6 RES23
2007 MA Massachusetts Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.6 0.1 2.2 2 Hispanic Maternal Race/Ethnicity 42.27687 -72.08269 CLA8 TOP43 QUO143 25 ETH2 BOC6 RES23
2007 IL Illinois Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.4 0.2 0.6 12 White, non-Hispanic Maternal Race/Ethnicity 40.48501 -88.99771 CLA8 TOP43 QUO143 17 ETH4 BOC6 RES23
2007 DE Delaware Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 1.8 0.6 5.4 4 Hispanic Maternal Race/Ethnicity 39.00883 -75.57774 CLA8 TOP43 QUO143 10 ETH2 BOC6 RES23
2007 MO Missouri Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.8 0.5 1.5 18 White, non-Hispanic Maternal Race/Ethnicity 38.63579 -92.56630 CLA8 TOP43 QUO143 29 ETH4 BOC6 RES23
2007 AR Arkansas Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.3 0.1 1.0 2 Hispanic Maternal Race/Ethnicity 34.74865 -92.27449 CLA8 TOP43 QUO143 5 ETH2 BOC6 RES23
2007 RI Rhode Island Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.3 0.2 0.6 5 Hispanic Maternal Race/Ethnicity 41.70828 -71.52247 CLA8 TOP43 QUO143 44 ETH2 BOC6 RES23
2007 WV West Virginia Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO NA NA NA NA Hispanic Maternal Race/Ethnicity 38.66551 -80.71264 CLA8 TOP43 QUO143 54 ETH2 BOC6 RES23
2007 UT Utah Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.5 0.2 1.0 15 White, non-Hispanic Maternal Race/Ethnicity 39.36070 -111.58713 CLA8 TOP43 QUO143 49 ETH4 BOC6 RES23
2007 MA Massachusetts Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.5 0.1 1.9 2 White, non-Hispanic Maternal Race/Ethnicity 42.27687 -72.08269 CLA8 TOP43 QUO143 25 ETH4 BOC6 RES23
2007 AR Arkansas Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.5 0.2 1.1 18 White, non-Hispanic Maternal Race/Ethnicity 34.74865 -92.27449 CLA8 TOP43 QUO143 5 ETH4 BOC6 RES23
2007 SD South Dakota Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO NA NA NA NA Hispanic Maternal Race/Ethnicity 44.35313 -100.37353 CLA8 TOP43 QUO143 46 ETH2 BOC6 RES23
2007 HI Hawaii Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.4 0.1 2.5 1 White, non-Hispanic Maternal Race/Ethnicity 21.30485 -157.85775 CLA8 TOP43 QUO143 15 ETH4 BOC6 RES23
2007 VT Vermont Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO NA NA NA NA Hispanic Maternal Race/Ethnicity 43.62538 -72.51764 CLA8 TOP43 QUO143 50 ETH2 BOC6 RES23
2007 MD Maryland Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.1 0.1 0.3 8 White, non-Hispanic Maternal Race/Ethnicity 39.29058 -76.60926 CLA8 TOP43 QUO143 24 ETH4 BOC6 RES23
2007 MN Minnesota Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 1.1 0.2 7.4 1 Hispanic Maternal Race/Ethnicity 46.35565 -94.79420 CLA8 TOP43 QUO143 27 ETH2 BOC6 RES23
2007 IL Illinois Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.6 0.2 1.9 4 Hispanic Maternal Race/Ethnicity 40.48501 -88.99771 CLA8 TOP43 QUO143 17 ETH2 BOC6 RES23
2007 WA Washington Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.2 0.0 1.3 1 Hispanic Maternal Race/Ethnicity 47.52228 -120.47001 CLA8 TOP43 QUO143 53 ETH2 BOC6 RES23
2007 NY New York (excluding NYC) Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.4 0.1 1.0 4 Hispanic Maternal Race/Ethnicity 42.82700 -75.54397 CLA8 TOP43 QUO143 36 ETH2 BOC6 RES23
2007 OR Oregon Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.6 0.2 1.7 18 White, non-Hispanic Maternal Race/Ethnicity 44.56745 -120.15503 CLA8 TOP43 QUO143 41 ETH4 BOC6 RES23
2007 NC North Carolina Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.7 0.3 1.3 9 Hispanic Maternal Race/Ethnicity 35.46622 -79.15925 CLA8 TOP43 QUO143 37 ETH2 BOC6 RES23
2007 NJ New Jersey Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.2 0.1 0.7 3 White, non-Hispanic Maternal Race/Ethnicity 40.13057 -74.27369 CLA8 TOP43 QUO143 34 ETH4 BOC6 RES23
2007 NY New York (excluding NYC) Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.6 0.3 1.4 19 White, non-Hispanic Maternal Race/Ethnicity 42.82700 -75.54397 CLA8 TOP43 QUO143 36 ETH4 BOC6 RES23
2007 MI Michigan Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.5 0.3 1.1 12 White, non-Hispanic Maternal Race/Ethnicity 44.66132 -84.71439 CLA8 TOP43 QUO143 26 ETH4 BOC6 RES23
2007 NE Nebraska Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.4 0.1 2.3 1 Hispanic Maternal Race/Ethnicity 41.64104 -99.36572 CLA8 TOP43 QUO143 31 ETH2 BOC6 RES23
2007 CO Colorado Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.6 0.3 1.1 24 White, non-Hispanic Maternal Race/Ethnicity 38.84384 -106.13361 CLA8 TOP43 QUO143 8 ETH4 BOC6 RES23
2007 YC New York City Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.6 0.2 1.7 8 White, non-Hispanic Maternal Race/Ethnicity 42.82700 -75.54397 CLA8 TOP43 QUO143 36 ETH4 BOC6 RES23
2007 NE Nebraska Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.2 0.0 1.1 1 White, non-Hispanic Maternal Race/Ethnicity 41.64104 -99.36572 CLA8 TOP43 QUO143 31 ETH4 BOC6 RES23
2007 WY Wyoming Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.4 0.2 0.7 7 White, non-Hispanic Maternal Race/Ethnicity 43.23554 -108.10983 CLA8 TOP43 QUO143 56 ETH4 BOC6 RES23
2007 DE Delaware Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.2 0.1 0.7 2 White, non-Hispanic Maternal Race/Ethnicity 39.00883 -75.57774 CLA8 TOP43 QUO143 10 ETH4 BOC6 RES23
2007 WI Wisconsin Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.4 0.1 1.8 2 White, non-Hispanic Maternal Race/Ethnicity 44.39319 -89.81637 CLA8 TOP43 QUO143 55 ETH4 BOC6 RES23
2007 CO Colorado Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.4 0.2 0.9 11 Hispanic Maternal Race/Ethnicity 38.84384 -106.13361 CLA8 TOP43 QUO143 8 ETH2 BOC6 RES23
2007 GA Georgia Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.3 0.1 0.7 5 White, non-Hispanic Maternal Race/Ethnicity 32.83968 -83.62758 CLA8 TOP43 QUO143 13 ETH4 BOC6 RES23
2007 AK Alaska Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.6 0.2 1.6 12 White, non-Hispanic Maternal Race/Ethnicity 64.84508 -147.72206 CLA8 TOP43 QUO143 2 ETH4 BOC6 RES23
2007 RI Rhode Island Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.5 0.3 1.1 18 White, non-Hispanic Maternal Race/Ethnicity 41.70828 -71.52247 CLA8 TOP43 QUO143 44 ETH4 BOC6 RES23
2007 NC North Carolina Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.8 0.3 1.7 20 White, non-Hispanic Maternal Race/Ethnicity 35.46622 -79.15925 CLA8 TOP43 QUO143 37 ETH4 BOC6 RES23
2007 MN Minnesota Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.3 0.1 1.0 4 White, non-Hispanic Maternal Race/Ethnicity 46.35565 -94.79420 CLA8 TOP43 QUO143 27 ETH4 BOC6 RES23
2007 SC South Carolina Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.2 0.1 0.3 6 Hispanic Maternal Race/Ethnicity 33.99882 -81.04537 CLA8 TOP43 QUO143 45 ETH2 BOC6 RES23
2007 SC South Carolina Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.7 0.3 2.0 46 White, non-Hispanic Maternal Race/Ethnicity 33.99882 -81.04537 CLA8 TOP43 QUO143 45 ETH4 BOC6 RES23
2007 OH Ohio Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 5.7 0.8 31.2 1 Hispanic Maternal Race/Ethnicity 40.06021 -82.40426 CLA8 TOP43 QUO143 39 ETH2 BOC6 RES23
2007 WV West Virginia Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 1.0 0.5 1.9 31 White, non-Hispanic Maternal Race/Ethnicity 38.66551 -80.71264 CLA8 TOP43 QUO143 54 ETH4 BOC6 RES23
2007 OK Oklahoma Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.3 0.2 0.5 13 Hispanic Maternal Race/Ethnicity 35.47203 -97.52107 CLA8 TOP43 QUO143 40 ETH2 BOC6 RES23
2007 HI Hawaii Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.7 0.2 2.7 2 Hispanic Maternal Race/Ethnicity 21.30485 -157.85775 CLA8 TOP43 QUO143 15 ETH2 BOC6 RES23
2007 VT Vermont Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.6 0.3 1.2 11 White, non-Hispanic Maternal Race/Ethnicity 43.62538 -72.51764 CLA8 TOP43 QUO143 50 ETH4 BOC6 RES23
2007 OK Oklahoma Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.4 0.3 0.5 73 White, non-Hispanic Maternal Race/Ethnicity 35.47203 -97.52107 CLA8 TOP43 QUO143 40 ETH4 BOC6 RES23
2007 NJ New Jersey Infant Health Pregnancy Outcome Indicator of infant currently alive PRAMS NO 0.9 0.3 2.7 3 Hispanic Maternal Race/Ethnicity 40.13057 -74.27369 CLA8 TOP43 QUO143 34 ETH2 BOC6 RES23
view(filtered_mortality_race)

plot_infant_deaths <- ggplot(filtered_mortality_race, aes(x = break_out, fill = break_out)) +
  geom_bar() +
  labs(title = "Infant Deaths by Ethnicity",
       x = "Ethnicity",
       y = "Total Infant Deaths") +
  scale_fill_manual(values = c("Hispanic" = "blue", "Non-hispanic" = "green", "White, non-Hispanic" = "pink")) +
  theme_minimal()

print(plot_infant_deaths)

The plot_infant_deaths above shows a plot of infant deaths categorized by whether they were Hispanic or not. The graph shows that those who were not Hispanic had a higher infant death count than those who were Hispanic.

#Plot of Infant Mortality and Maternal Income

filtered_mortality_income <- cleaned_infant_mortality %>%
  filter(break_out_category == "Income (years 2004 and beyond)" &
         (break_out %in% c("Less than $10,000", "$25,000 to $49,999", "$50,000 or more")) &
         question == "Indicator of infant currently alive" & response == "NO")

view(filtered_mortality_income)

plot_infant_income <- ggplot(filtered_mortality_income, aes(x = break_out, fill = break_out)) +
  geom_bar() +
  labs(title = "Infant Deaths by Income",
       x = "Income",
       y = "Total Infant Deaths") +
  scale_fill_manual(values = c("Less than $10,000" = "blue", "$25,000 to $49,999" = "purple", "$50,000 or more" = "pink")) +
  theme_minimal()

print(plot_infant_income)

creating a linear regression

merged_data <- left_join(cleaned_alc_2007, cleaned_infant_mortality, by = "year") %>%
  select(location_abbr.x, location_abbr.y, location_desc.x, location_desc.y, topic.x, topic.y, question.x, response.x, class.y, topic.y, question.y, break_out_category.y, response.y)
## Warning in left_join(cleaned_alc_2007, cleaned_infant_mortality, by = "year"): Detected an unexpected many-to-many relationship between `x` and `y`.
## i Row 1 of `x` matches multiple rows in `y`.
## i Row 1 of `y` matches multiple rows in `x`.
## i If a many-to-many relationship is expected, set `relationship =
##   "many-to-many"` to silence this warning.